<!DOCTYPE HTML>
<html>
<head>
<title>Break | AutoHotkey</title>
<meta name="description" content="The Break statement exits (terminates) any type of loop statement." />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>Break</h1>
<p>退出(终止) 任意类型的<a href="../Language.htm#loop-statement">循环语句</a>.</p>
<pre class="Syntax"><span class="func">Break</span> <span class="optional">, LoopLabel</span></pre>

<h2>参数</h2>
<dl>
  <dt>LoopLabel <span class="ver">[AHK_L 59+]</span></dt>
  <dd><em>LoopLabel</em> 标识此语句应该应用于哪层循环; 使用<a href="../misc/Labels.htm">标签名</a>或嵌套层级的数值表示. 如果省略或为 1, 此语句应用于它所在的最内层循环. <em>LoopLabel</em> 必须为常量, 不支持变量和表达式. 如果指定 <a href="../misc/Labels.htm">label</a>, 则它必须直接指向<a href="../Language.htm#loop-statement">循环语句</a>.</dd>
</dl>

<h2>备注</h2>
<p>鼓励使用 Break 和 <a href="Continue.htm">Continue</a> 代替 <a href="Goto.htm">goto</a> 因为它们通常让脚本更容易阅读和维护.</p>
<h2>相关</h2>
<p><a href="Continue.htm">Continue</a>, <a href="Loop.htm">Loop</a>, <a href="While.htm">While 循环</a>, <a href="For.htm">For 循环</a>, <a href="Block.htm">区块</a>, <a href="../misc/Labels.htm">标签</a></p>
<h2>示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Loop
{
    <em>; ...</em>
    if (var &gt; 25)
        break
    <em>; ...</em>
    if (var &lt;= 5)
        continue
}</pre>
</div>

<div class="ex" id="ExBreakOuter">
<p><a href="#ExBreakOuter">#2</a>: 从内嵌循环内部退出到外层循环.</p>
<pre>outer:
Loop 3
{
    x := A_Index
    Loop 3
    {
        if (x*A_Index = 6)
            break outer  <em>; 等同于 <b>break 2</b> 或 <b>goto break_outer</b>.</em>
        MsgBox %x%,%A_Index%
    }
}
break_outer: <em>; 用于 goto 命令.</em>
</pre>
</div>

</body>
</html>